#include "rpg_object.h"
#include <string.h>

RPG_Object::RPG_Object()
{
//example:	hp.value = 0;
#ifndef OBJ_INIT_VALUE_ZERO
#define OBJ_INIT_VALUE_ZERO(element) element##.value = 0;
#endif

	OBJ_INIT_VALUE_ZERO(hp);
	OBJ_INIT_VALUE_ZERO(mp);
	OBJ_INIT_VALUE_ZERO(fire);
	OBJ_INIT_VALUE_ZERO(water);
	OBJ_INIT_VALUE_ZERO(darkness);
	OBJ_INIT_VALUE_ZERO(holy);
	OBJ_INIT_VALUE_ZERO(attack);
	OBJ_INIT_VALUE_ZERO(defense);

#undef OBJ_INIT_VALUE_ZERO

	memset(name,0,sizeof(name));
	memset(description,0,sizeof(description));
}

RPG_Object::~RPG_Object(){}


int RPG_Object::Obj_fire_attack(){return fire.value * attack.value;}
int RPG_Object::Obj_water_attack(){return water.value * attack.value;}
int RPG_Object::Obj_darkness_attack(){return darkness.value * attack.value;}
int RPG_Object::Obj_holy_attack(){return holy.value * attack.value;}
int RPG_Object::Obj_fire_defense(){return fire.value * defense.value;}
int RPG_Object::Obj_water_defense(){return water.value * defense.value;}
int RPG_Object::Obj_darkness_defense(){return darkness.value * defense.value;}
int RPG_Object::Obj_holy_defense(){return holy.value * defense.value;}


//example:	this->hp.value = hp;
#ifndef OBJ_VALUE_SET
#define OBJ_VALUE_SET(var) this->##var##.value = var;
#endif

void RPG_Object::setHpMp(int hp,int mp)
{
	OBJ_VALUE_SET(hp);
	OBJ_VALUE_SET(mp);
}
void  RPG_Object::setElement(int fire,int water,int darkness,int holy)
{
	OBJ_VALUE_SET(fire);
	OBJ_VALUE_SET(water);
	OBJ_VALUE_SET(darkness);
	OBJ_VALUE_SET(holy);
}

void RPG_Object::setAttackAndDefense(int attack,int defense)
{
	OBJ_VALUE_SET(attack);
	OBJ_VALUE_SET(defense);
}
#undef OBJ_VALUE_SET


bool obj_setstr(char* dst,char* src,size_t dst_len)
{
	size_t len = strlen(src);
	if( len > dst_len - 1)
		return false;
	memset(dst,0,dst_len);
	memcpy(dst,src,len);
	return true;
}

bool RPG_Object::setName(char* name)
{
	return obj_setstr(this->name,name,sizeof(this->name));
}
bool RPG_Object::setDescription(char* description)
{
	return obj_setstr(this->description,description,sizeof(this->description));
}